home *** CD-ROM | disk | FTP | other *** search
- /* #include files */
-
- #include "A4Stuff.h"
- #include "SetupA4.h"
- #include "TestGlobals.h"
-
- /* #defines */
-
- #define kINITid 0
-
- #define SEGMENTED true /* define if we have a multiple segment INIT */
- #define kNumSegments 2 /* total number of segments, including INIT resource itself */
-
- /* some globals local to this file */
-
- long gLong;
- short gShort;
- char gChar;
-
- /* SystemTask patch stuff */
-
- typedef pascal void (*SystemTaskProc)(void);
- SystemTaskProc gOldSystemTaskAddr;
- pascal void SystemTaskPatch(void);
-
- /* main */
-
- void main(void)
- {
- long oldA4;
- Handle h;
-
- #ifdef USE_DEBUGGER_CALLS
- Debugger();
- #endif
-
- /* set up our A4 context for _this file_ */
- oldA4 = SetCurrentA4();
- RememberA4();
-
- /* detach ourselves */
- h = Get1Resource('INIT', kINITid);
- if (h) DetachResource(h);
-
- /* initialize the globals in _this file_ */
- gLong = kLongValue;
- gShort = kShortValue;
- gChar = kCharValue;
- gOldSystemTaskAddr = 0L;
-
- /* initialize the globals in the _other file_ */
- /* this also forces the code in the other segment to be loaded */
- /* we must force all other segments to be loaded at this point */
- /* so we can detach them below */
- InitGlobals(kLongValue, kShortValue, kCharValue);
-
- /* now that we are sure that all segments have been loaded */
- /* (since we called at least one routine in each segment) */
- /* we can continue by detaching each one */
- #ifdef SEGMENTED
- {
- short i;
- for (i=kINITid+1;i<kNumSegments;++i) {
- h = Get1Resource('INIc', i); /* should NOT fail since each segment should already be loaded and locked */
- if (h) DetachResource(h);
- }
- }
- #endif
-
- /* patch SystemTask */
- gOldSystemTaskAddr = (SystemTaskProc)GetToolTrapAddress(_SystemTask);
- SetToolTrapAddress((UniversalProcPtr)SystemTaskPatch, _SystemTask);
-
- /* restore the a4 world */
- SetA4(oldA4);
- }
-
- /* SystemTaskPatch */
-
- pascal void SystemTaskPatch(void)
- {
- long oldA4;
-
- #ifdef USE_DEBUGGER_CALLS
- Debugger();
- #endif
-
- /* use the global data in _this file_ */
- oldA4 = SetUpA4();
-
- /* verify the globals in _this file_ */
- if (gLong != kLongValue) SysBeep(0);
- if (gShort != kShortValue) SysBeep(0);
- if (gChar != kCharValue) SysBeep(0);
-
- /* test the globals in the _other file_ */
- TestGlobals();
-
- /* call through to the original SystemTask */
- gOldSystemTaskAddr();
-
- /* test the globals in the _other file_ again */
- TestGlobals();
-
- /* verify the globals in _this file_ again */
- if (gLong != kLongValue) SysBeep(0);
- if (gShort != kShortValue) SysBeep(0);
- if (gChar != kCharValue) SysBeep(0);
-
- /* restore the a4 world */
- RestoreA4(oldA4);
- }
-
-